<template>
  <div>
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="onSelect"
    />
    <h3 v-if="list.length===0">暂无地址快去添加~~~</h3>
      <goback></goback>
  </div>
  
</template>

<script>
import goback from "../../components/goback.vue";
import { reqAddressList } from "../../http/api";
export default {
  components: {
    goback,
  },
  data() {
    return {
      chosenAddressId: "1",
      list: [
        // {
        //   id: '1',
        //   name: '张三',
        //   tel: '13000000000',
        //   address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        //   isDefault: true,
        // }
      ],
    };
  },
  mounted() {
    reqAddressList({ uid: JSON.parse(localStorage.getItem("user")).uid }).then(
      (res) => {
        console.log(res);
        var list = res.data.list ? res.data.list : [];
        this.list = list.map((item) => {
          return {
            id: item.id,
            name: item.username,
            tel: item.userphone,
            address: item.location + item.useraddress,
            isDefault: item.status === 1,
          };
        });
      }
    );
  },
  methods: {
    onAdd() {
      this.$router.push("/xaddress");
    },
    onEdit(item, index) {
      // console.log(item);
      // console.log(index);
      this.$router.push("/xaddress?id="+item.id)
    },
    onSelect(item,index){
      this.$router.push("/qrdd?addressId="+item.id)
    }
  },
};
</script>

<style scoped>
.btn {
  background-color: red;
  border: none;
  position: absolute;
  bottom: 0;
  border-radius: 0.6rem;
}
h3 {
  text-align: center;
  font-size: 0.6rem;
}
</style>